package com.hyh.fireworks.exception;


import com.hyh.fireworks.common.result.AjaxResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/**
 * 全局异常处理器
 *
 * @author Summerday
 */

@RestControllerAdvice
public class GlobalExceptionHandler {

    private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);


    @ExceptionHandler(CustomException.class)
    public AjaxResult customExceptionHandle(HttpServletRequest request, CustomException e) {
        AjaxResult info = AjaxResult.error(e.getMessage());
        //unAuth(request);
        log.error("异常! ip : {}, method : {} , uri : {} , msg : {}", request.getRemoteAddr(), request.getMethod(), request.getRequestURI(), e.getMessage());
        return info;
    }

    @ExceptionHandler(Exception.class)
    public AjaxResult defaultHandle(Exception e) {
        AjaxResult info = AjaxResult.error("系统异常!");
        log.error("异常!msg : {}", e.getMessage());
        return info;
    }





}
